package com.dingding.order.core.cancel.dao.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.log4j.Logger;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.dingding.common.core.base.dao.impl.BaseDaoImpl;
import com.dingding.common.core.base.daox.ICriteriaBaseDao;
import com.dingding.common.core.base.daox.ISQLBaseDao;
import com.dingding.common.core.beans.special.UserspecialorderT;
import com.dingding.order.core.cancel.dao.ISpecialCancelOrderDao;
import com.dingding.order.core.cancel.sql.CancelOrderSql;
import com.dingding.order.dto.cancel.special.CancelSpecialOrderNoticeDTO;
import com.dingding.order.dto.cancel.special.PushAutoCancelSpecialOrderDTO;

/**
 * 
 * @ClassName: SpecialCancelOrderDaoImpl 
 * @Description: 取消专车订单DAO实现类 
 * @author YHQ
 * @date 2016年8月23日 下午3:33:49
 * @since V2.4.0
 * 
 */
@Component("specialCancelOrderDao")
public class SpecialCancelOrderDaoImpl extends BaseDaoImpl<UserspecialorderT> implements ISpecialCancelOrderDao{

	@Resource(name="criteriaBaseDao")
	private ICriteriaBaseDao criteriaBaseDao;
	
	@Resource(name="SQLBaseDao")
	private ISQLBaseDao sqlBaseDao;
	
	private Logger log = Logger.getLogger(this.getClass());
	
	/**
	 * 
	 * @Title: getUserSpecialOrdertInfo 
	 * @Description: 根据订单Id获取专车订单信息
	 * @param oid 订单Id
	 * @author YHQ 
	 * @since V2.4.0
	 * @return UserspecialorderT    返回类型
	 * 
	 */
	@Override
	@Transactional(readOnly=true)
	public UserspecialorderT getUserSpecialOrdertInfo(String oid) {
		
		Criterion criterion = Restrictions.eq("specialOrderId", oid);
		
		try {
			return criteriaBaseDao.queryCriteriaListUnique(UserspecialorderT.class,criterion);
		} catch (Exception e) {
			log.error("根据用户Id获取专车未完成订单时出现异常   类："+this.getClass()+" getUserSpecialOrdertInfo()", e);
		}
		
		return null;
	}

	/**
	 * 
	 * @Title: getNoticeInfo 
	 * @Description: 获取取消订单通知信息
	 * @param oid 订单Id
	 * @param cancelType 取消类型   1:乘客取消 2:车主取消 
	 * @author YHQ 
	 * @return CancelSpecialOrderSQL    返回类型
	 * 
	 */
	@Override
	public CancelSpecialOrderNoticeDTO getNoticeInfo(String oid, int cancelType) {
		
		try {
			// 根据订单Id和取消人，获取取消推送内容
			List<CancelSpecialOrderNoticeDTO> cancelOrderNotices = sqlBaseDao.listSqlToCustomBean(CancelSpecialOrderNoticeDTO.class, CancelOrderSql.cancelSpecialOrderNoticeInfo(cancelType), oid);
			
			if(cancelOrderNotices != null && cancelOrderNotices.size() > 0){
				
				return cancelOrderNotices.get(0);
			}
		} catch (Exception e) {
			log.error("获取取消订单通知信息时出现异常   类："+this.getClass()+" getNoticeInfo()", e);
		}
		
		return null;
	}

	/**
	 * 
	 * @Title: getSpecialOrderts 
	 * @Description: 获取待自动取消订单
	 * @return List<UserspecialorderT> 
	 * @author SUNZHICHENG  
	 * @date  2016年9月5日 下午4:41:57
	 * @since v2.4.0
	 * @modify by hufan 注释无用查询
	 */
	@Override
	@Transactional(readOnly=true)
	public List<UserspecialorderT> getSpecialOrderts() {
		// 将待自动取消订单列表转为类型为List<UserspecialorderT>的集合中
		 List<UserspecialorderT> orders=sqlBaseDao.listSqlToCustomBean(UserspecialorderT.class, CancelOrderSql.AUTO_CANCEL_SPECIAL_ORDER_LIST);
		if (orders!=null && orders.size()>0) {
			return orders;
		}
		return null;
	}
	
	
	/**
	 * 
	 * @Title: getPushCancelSpecialOrder 
	 * @Description: 专车-自动取消订单推送消息 
	 * @param suid 用户id
	 * @return PushAutoCancelTaxiOrderDTO 
	 * @author SUNZHICHENG  
	 * @date  2016年9月5日 下午5:53:00
	 * @since v2.4.0
	 */
	@Override
	@Transactional(readOnly=true)
	public PushAutoCancelSpecialOrderDTO getPushCancelSpecialOrder(String suid) {
		// 获取专车车订单自动取消推送消息 
		 List<PushAutoCancelSpecialOrderDTO> listSqlToCustomBean = sqlBaseDao.listSqlToCustomBean(PushAutoCancelSpecialOrderDTO.class,CancelOrderSql.GET_SPECIAL_PUSH_INFO, suid);
		if (listSqlToCustomBean!=null && listSqlToCustomBean.size()>0) {
			return listSqlToCustomBean.get(0);
		}
		return null;
	}

	
	
}
